package nettypro.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @ClassName NIOClient
 * @Description TODO
 * @Author zeny
 * @Date 2020/3/22 0022 14:56
 */
public class NIOClient {
    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        socketChannel.configureBlocking(false);
        InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 6666);
        if (!socketChannel.connect(inetSocketAddress)) {
            while (!socketChannel.finishConnect()) {
                System.out.println("客户端连接需要时间");
            }
        }
        String string =  "hello, 扇规格";
        ByteBuffer buffer = ByteBuffer.wrap(string.getBytes());
        socketChannel.write(buffer);
        System.in.read();
        socketChannel.close();
    }
}
